<template>
	<view>
		<view class="uni-padding-wrap uni-common-mt">
			<uni-segmented-control :current="current" :values="items" style-type="text"
				active-color="#007aff" @clickItem="onClickItem" />
		</view>
		<view class="content">
			<view v-if="current === 0">
				<text class="content-text">
					<uni-forms :modelValue="addCustomer">
						<uni-forms-item label="客户类型" name="type">
							<uni-easyinput type="text" v-model="addCustomer.type" placeholder="请输入客户类型" />
						</uni-forms-item>
						<uni-forms-item label="客户姓名" name="name">
							<uni-easyinput type="text" v-model="addCustomer.name" placeholder="请输入客户姓名" />
						</uni-forms-item>
						<uni-forms-item label="客户姓别" name="gender">
							<uni-easyinput type="text" v-model="addCustomer.gender" placeholder="请输入客户性别" />
						</uni-forms-item>
						<uni-forms-item label="年龄" name="age">
							<uni-easyinput type="text" v-model="addCustomer.age" placeholder="请输入年龄" />
						</uni-forms-item>
						<uni-forms-item label="联系电话" name="contactPhone">
							<uni-easyinput type="text" v-model="addCustomer.contactPhone" placeholder="请输入联系电话" />
						</uni-forms-item>
						<uni-forms-item label="身份证号" name="idNumber">
							<uni-easyinput type="text" v-model="addCustomer.idNumber" placeholder="请输入身份证号" />
						</uni-forms-item>
						<uni-forms-item label="楼盘名称" name="propertyName">
							<uni-easyinput type="text" v-model="addCustomer.propertyName" placeholder="请输入楼盘名称" />
						</uni-forms-item>
						<uni-forms-item label="户型" name="houseType">
							<uni-easyinput type="text" v-model="addCustomer.houseType" placeholder="请输入户型" />
						</uni-forms-item>
						<uni-forms-item label="面积" name="houseSize">
							<uni-easyinput type="text" v-model="addCustomer.houseSize" placeholder="请输入面积" />
						</uni-forms-item>
						<uni-forms-item label="省份" name="province">
							<uni-easyinput type="text" v-model="addCustomer.province" placeholder="请输入省份" />
						</uni-forms-item>
						<uni-forms-item label="城市" name="city">
							<uni-easyinput type="text" v-model="addCustomer.city" placeholder="请输入城市" />
						</uni-forms-item>
						<uni-forms-item label="区县" name="district">
							<uni-easyinput type="text" v-model="addCustomer.district" placeholder="请输入区县" />
						</uni-forms-item>
						<uni-forms-item label="详细地址" name="propertyAddr">
							<uni-easyinput type="text" v-model="addCustomer.propertyAddr" placeholder="请输入详细地址" />
						</uni-forms-item>
					</uni-forms>
				</text>
				<view class="uni-padding-wrap uni-common-mt">
					<view class="button-sp-area">
						<button type="primary" plain="true" @click="saveCustomer">保存</button>
					</view>
				</view>
			</view>
			<view v-if="current === 1">
				<text class="content-text">
					<uni-forms :modelValue="addCustomerFollowUp">
						<uni-forms-item label="跟单人" name="merchandiser">
							<uni-easyinput type="text" v-model="addCustomerFollowUp.merchandiser" placeholder="请输入跟单人" />
						</uni-forms-item>
						<uni-forms-item label="客情描述" name="customerDescribe">
							<uni-easyinput type="text" v-model="addCustomerFollowUp.customerDescribe" placeholder="请输入客情描述" />
						</uni-forms-item>
						<uni-forms-item label="客户来源" name="source">
							<uni-easyinput type="text" v-model="addCustomerFollowUp.source" placeholder="请输入客户来源" />
						</uni-forms-item>
					</uni-forms>
			    </text>
				<view class="uni-padding-wrap uni-common-mt">
					<view class="button-sp-area">
						<button type="primary" plain="true" @click="saveCustomerFollowUp">保存</button>
					</view>
				</view>
			</view>
			<view v-if="current === 2">
				<text class="content-text">
					<uni-forms :modelValue="addCustomerFollowUp">
						<uni-forms-item label="是否可量房" name="isQuantityHouse">
							<uni-easyinput type="text" v-model="addCustomerFollowUp.isQuantityHouse" placeholder="请输入是否可量房" />
						</uni-forms-item>
						<uni-forms-item label="预约量房时间" name="appointmentTime">
							<uni-datetime-picker type="datetime" return-type="timestamp" v-model="addCustomerFollowUp.appointmentTime" placeholder="请选择预约量房时间"/>
						</uni-forms-item>
						<uni-forms-item label="实际量房时间" name="physicalTime">
							<uni-datetime-picker type="datetime" return-type="timestamp" v-model="addCustomerFollowUp.physicalTime" placeholder="请选择实际量房时间"/>
						</uni-forms-item>
						<uni-forms-item label="量房人" name="quantityHouseName">
							<uni-easyinput type="text" v-model="addCustomerFollowUp.quantityHouseName" placeholder="请输入量房人" />
						</uni-forms-item>
						<uni-forms-item label="量房描述" name="remark">
							<uni-easyinput type="textarea" v-model="addCustomerFollowUp.remark" placeholder="请输入量房描述" />
						</uni-forms-item>
					</uni-forms>
				</text>
				<view class="uni-padding-wrap uni-common-mt">
					<view class="button-sp-area">
						<button type="primary" plain="true" @click="saveCustomerFollowUp">保存</button>
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script setup>
import { ref } from 'vue';

const addCustomer = ref({
	type:'',
	name:'',
	gender:'',
	age:'',
	contactPhone:'',
	idNumber:'',
	propertyName:'',
	houseType:'',
	houseSize:'',
	province:'',
	city:'',
	district:'',
	propertyAddr:''
});

const saveCustomer = ()=>{
	uni.request({
		method:'POST',
		url: 'http://localhost:8080/api/crm/customer/insertCustomer',
		data: addCustomer.value,
		header: {
			'token': '1234-4567-8901-2345'
		},
		success: (res) => {
			if(res.data.code == 2000){
				uni.showToast({
					icon: 'success',
					title: '保存成功'
				})
			} else {
				uni.showToast({
					icon: 'error',
					title: res.data.msg
				});
			}
		}
	})
};

const addCustomerFollowUp = ref({
	merchandiser:'',
	customerDescribe:'',
	source:'',
	isQuantityHouse:'',
	appointmentTime:'',
	physicalTime:'',
	quantityHouseName:'',
	remark:''
});

const saveCustomerFollowUp = ()=>{
	uni.request({
		method:'POST',
		url: 'http://localhost:8080/api/crm/customer/insertCustomerFollowUp',
		data: addCustomerFollowUp.value,
		header: {
			'token': '1234-4567-8901-2345'
		},
		success: (res) => {
			if(res.data.code == 2000){
				uni.showToast({
					icon: 'success',
					title: '保存成功'
				})
			} else {
				uni.showToast({
					icon: 'error',
					title: res.data.msg
				});
			}
		}
	})
};

const current = ref(0);
const items = ref(['基本信息', '客情跟踪', '量房信息']);
const onClickItem = (e) => {
	if (current.value !== e.currentIndex) {
		current.value = e.currentIndex
		}
	};


</script>

<style>
	       
</style>
